require('dotenv').config();

const {
  MONGODB_ROOT_USER,
  MONGODB_ROOT_PASSWORD,
  MONGODB_HOST,
  MONGODB_PORT,
  MONGODB_DATABASE,
} = process.env;

if (!MONGODB_HOST || !MONGODB_PORT || !MONGODB_DATABASE) {
  throw new Error('Missing required MongoDB environment variables for migration');
}

const credentials = MONGODB_ROOT_USER && MONGODB_ROOT_PASSWORD
  ? `${MONGODB_ROOT_USER}:${MONGODB_ROOT_PASSWORD}@`
  : '';

const mongoURI = `mongodb://${credentials}${MONGODB_HOST}:${MONGODB_PORT}`;

module.exports = {
  mongodb: {
    url: mongoURI,
    databaseName: MONGODB_DATABASE,
    options: {
      useNewUrlParser: true,
      useUnifiedTopology: true,
    }
  },
  migrationsDir: "src/mongodb/migrations",
  changelogCollectionName: "changelog",
  migrationFileExtension: ".js"
};

